package com.utils;

import com.alibaba.excel.EasyExcel;
import com.bean.SeatExcel;
import com.bean.SeatLog;
import com.service.SeatLogService;
import org.junit.Test;
import org.springframework.beans.BeanUtils;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import java.util.ArrayList;
import java.util.List;

/**
 * @author 夏天
 * @date 2020年11月09日 8:29
 */
public class Mytest {


    @Test
    public void test() {
        ApplicationContext ac;
        ac = new ClassPathXmlApplicationContext("application-context.xml");
        String fileName = "F:\\javaee\\reserve\\" + System.currentTimeMillis() + ".xlsx";
        SeatLogService sc = ac.getBean(SeatLogService.class);
        List<SeatLog> list = sc.list();
        List<SeatExcel> seatExcelList = new ArrayList<>();
        for (SeatLog seatLog : list) {
            SeatExcel seatExcel = new SeatExcel();
            BeanUtils.copyProperties(seatLog, seatExcel);
            seatExcelList.add(seatExcel);
        }
        // 如果这里想使用03 则 传入excelType参数即可
        EasyExcel.write(fileName, SeatExcel.class).sheet("模板").doWrite(seatExcelList);
    }
}
